package cn.edu.web;

import cn.edu.pojo.All;
import cn.edu.pojo.PageBean;
import cn.edu.pojo.thesis;
import cn.edu.service.impl.lead_TeacherServiceImpl;
import cn.edu.service.impl.lead_thesisServiceImpl;
import cn.edu.service.lead_TeacherService;
import cn.edu.service.lead_thesisService;
import com.alibaba.fastjson.JSON;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.BufferedReader;
import java.io.IOException;

/**
 * @author Davey chan
 */
@WebServlet("/leadThesis/*")
public class lead_thesisServlet extends BaseServlet {
    private lead_thesisService tService = new lead_thesisServiceImpl();


    //分页查询
    public void selectByPage(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //        处理中文乱码
        request.setCharacterEncoding("utf-8");
       //接受当前页码，和每页展示条数
        String _currentPage = request.getParameter("currentPage");
        String _pageSize = request.getParameter("pageSize");
        String thesisTimes=request.getParameter("thesisTime");


        int currentPage = Integer.parseInt(_currentPage);
        int pageSize= Integer.parseInt(_pageSize);
//获取查询的封装对象


        BufferedReader br=request.getReader();
        String s = br.readLine();
        //        将JSON字符串转成JAVA对象
        thesis t = JSON.parseObject(s, thesis.class);
        if(!thesisTimes.equals("null") && thesisTimes.length()>0 ){
            System.out.println("hh");
            String[] split = thesisTimes.split(",");
            t.setBeginTime(split[0]);
            t.setEndTime(split[1]);
            System.out.println(split[0]);
        }
        PageBean<thesis> pageBean = tService.selectByPageAndcondition(currentPage, pageSize,t);


//将集合转换成JSON数据，也叫序列化
        String jsonString = JSON.toJSONString(pageBean);
//        响应数据
        response.setContentType("text/json;charset=utf-8");
        response.getWriter().write(jsonString);
    }


}
